<template>
    <div>
      <el-page-header @back="goBack" content="问题反馈">
      </el-page-header>
      <div class="questionForm">
        <textarea v-model="question" placeholder="请输入需要反馈的问题"> </textarea><br>
      <button @click="contactSupport">反馈问题</button>
    </div>
    </div>
  </template>
  
  <script>
  import axios from 'axios';
  import { Toast } from 'vant';
  export default {
    data() {
      return {
        question: '',
        username: '',
      };
    },
  
    methods: {
        contactSupport() {
          if(!this.question){
            Toast('请输入反馈内容')
          }else{
      const userNameJson = localStorage.getItem("user") || '';
      const userNameData = JSON.parse(userNameJson);
      this.username = userNameData.username;
        axios.post('http://localhost:8081/springboot01/user/feedback',
            {
              username: this.username,
              question: this.question
            },
            {
              headers: {
                'Content-Type': 'application/json'
              }
            }
        )
            .then(response => {
              console.log('Response data:', response.data);
              if (response.data.msg === "请求成功!") {
               Toast('反馈成功')
              }
            })
            .catch(error => {
              console.error('反馈失败:',error);
              this.error = '反馈失败，请稍后再试.';
            });
        }},
      goBack() {
        this.$router.go(-1);
      },
    },
  
  
  };
  </script>
  
<style>
.questionForm{
margin: 200px;
text-align: center;
}

</style>